package mshop.com.schild_kotlin.fragments

import android.os.Bundle
import android.support.v7.widget.GridLayoutManager
import kotlinx.android.synthetic.main.fragment_home.*
import mshop.com.schild_kotlin.R
import mshop.com.schild_kotlin.adapters.FindAdapter
import mshop.com.schild_kotlin.base.BaseFragment
import mshop.com.schild_kotlin.entitys.FindBean
import mshop.com.schild_kotlin.mvp.base.BaseContract
import mshop.com.schild_kotlin.mvp.presenter.FindPresenter
import mshop.com.schild_kotlin.utils.ItemGridLayoutDecoration

/**
 * Created by mayi on 2018/5/23.
 * @Autor CaiWF
 * @Email 401885064@qq.com
 * @TODO
 */

class FindFragment : BaseFragment(), BaseContract.View<MutableList<FindBean>> {
    var findAdapter: FindAdapter = FindAdapter()
    var mPresenter: FindPresenter? = null

    companion object {
        fun getInstall(): FindFragment {
            val home_fragment = FindFragment()
            val bundle = Bundle()
            home_fragment.arguments = bundle
            return home_fragment
        }
    }


    override fun initView() {
        mPresenter = context?.let { FindPresenter(it, this) }
        recycle_view.layoutManager = GridLayoutManager(context,2)
        recycle_view.addItemDecoration(ItemGridLayoutDecoration(resources.getDimensionPixelOffset(R.dimen.item_decoration),2))
        recycle_view.adapter=findAdapter
    }

    override fun getLayoutResources(): Int {
        return R.layout.fragment_home
    }

    override fun setData(entity: MutableList<FindBean>) {
        findAdapter.datas = entity
        findAdapter.notifyDataSetChanged()
        if (refreshLayout!!.isRefreshing) {
            refreshLayout?.isRefreshing = false
        }

    }

    override fun onRefresh() {
        mPresenter?.start()
    }

    override fun getNeedRefresh(): Boolean {
        return true
    }

}